/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.cloud.feign.domain.property;

import java.time.Duration;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
 * feign 相关属性.
 *
 * @author zengdegui
 * @since 2020/9/20
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "feign")
public class FeignProperty {

    /**
     * feign 请求配置.
     */
    @Builder.Default
    @NestedConfigurationProperty
    private FeignRequestConfig request = new FeignRequestConfig();

    /**
     * feign 重试策略配置.
     */
    @Builder.Default
    @NestedConfigurationProperty
    private FeignRetryConfig retry = new FeignRetryConfig();

    /**
     * feign 统一异常解码配置.
     */
    @Builder.Default
    @NestedConfigurationProperty
    private FeignErrorConfig error = new FeignErrorConfig();

    /**
     * feign 请求相关属性.
     *
     * @author zengdegui
     * @since 2023/6/1
     */
    @Data
    @SuperBuilder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FeignRequestConfig {

        /**
         * 是否启用.
         */
        @Builder.Default
        private Boolean enabled = Boolean.TRUE;
    }

    /**
     * feign 重试策略相关属性.
     *
     * @author zengdegui
     * @since 2023/6/1
     */
    @Data
    @SuperBuilder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FeignRetryConfig {

        /**
         * 是否启用.
         */
        @Builder.Default
        private Boolean enabled = Boolean.FALSE;

        /**
         * 初始间隔时间（单位：秒）.
         */
        @Builder.Default
        private Duration period = Duration.ofSeconds(1);

        /**
         * 最大重试间隔时间（单位：秒）.
         */
        @Builder.Default
        private Duration maxPeriod = Duration.ofSeconds(5);

        /**
         * 最大重试次数.
         */
        @Builder.Default
        private Integer maxAttempts = 3;
    }

    /**
     * feign 统一异常解码相关属性.
     *
     * @author zengdegui
     * @since 2023/6/1
     */
    @Data
    @SuperBuilder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FeignErrorConfig {

        /**
         * 是否启用.
         */
        @Builder.Default
        private Boolean enabled = Boolean.TRUE;
    }
}
